package main

import (
	"bytes"
	"fmt"
)

func main () {
	//切片共享内存
	foo := make([]int, 5)
	foo[3] = 42
	foo[4] = 100
	bar := foo[1:4]
	//fmt.Println(foo, bar)
	bar[1] = 99
	//fmt.Println(foo, bar)

	//append时，cap不足切片重新分配内存
	a := make([]int, 32)
	b := a[1:16]
	//fmt.Println(a, b)
	//append在cap不够用时才会重新分配内存，够用时不会重新分配
	a = append(a, 1)
	a[2] = 42
	fmt.Println(a, b)

	//append，cap足够时不会重新分配内存
	path := []byte("AAAA/BBBBBBBB")
	sepIndex := bytes.IndexByte(path, '/')
	dir1 := path[:sepIndex:sepIndex]
	dir2 := path[sepIndex+1:]
	fmt.Println("dir1 => ", string(dir1))
	fmt.Println("dir2 => ", string(dir2))
	fmt.Println(cap(dir1), len(dir1), cap(dir2), len(dir2))
	dir1 = append(dir1, "suffix"...)
	fmt.Println("dir1 => ", string(dir1))
	fmt.Println("dir2 => ", string(dir2))
	fmt.Println(cap(dir1), len(dir1), cap(dir2), len(dir2))



}

